package com.example.mybaseapp.util

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData


/**
 * 事件总线工具类
 * 如果value和之前一样，则不会触发observe
 * 修改之后，再修改回来，也不会触发observe
 */
object LiveDataBus {
    /**福币发生变化*/
    const val Fu_Coin_Change = "Fu_Coin_Change"

    private val bus: MutableMap<String, MutableLiveData<Any>> = HashMap()

    @Synchronized
    fun <T> with(key: String): MutableLiveData<T> {
        if (!bus.containsKey(key)) {
            bus[key] = MutableLiveData()
        }
        @Suppress("UNCHECKED_CAST")
        return bus[key] as MutableLiveData<T>
    }

}